<?php
/**
 * 简单测试二级分类功能
 */

require_once __DIR__ . '/backend/support/bootstrap.php';

use app\model\GoodsCatModel;

echo "=== 测试二级分类功能 ===\n";

try {
    // 检查是否有分类数据
    $mainCategories = GoodsCatModel::where('status', 1)
        ->where('fid', 0)
        ->get();
    
    echo "一级分类数量: " . $mainCategories->count() . "\n";
    
    if ($mainCategories->count() > 0) {
        $firstCategory = $mainCategories->first();
        echo "第一个分类: ID={$firstCategory->id}, 名称={$firstCategory->name}\n";
        
        // 获取该分类的二级分类
        $subCategories = GoodsCatModel::where('status', 1)
            ->where('fid', $firstCategory->id)
            ->get();
        
        echo "二级分类数量: " . $subCategories->count() . "\n";
        
        if ($subCategories->count() > 0) {
            echo "二级分类列表:\n";
            foreach ($subCategories as $subCat) {
                echo "- ID: {$subCat->id}, 名称: {$subCat->name}\n";
            }
        }
    } else {
        echo "没有找到一级分类数据\n";
    }
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
}

echo "\n测试完成！\n"; 